<?php

namespace App\model;

use App\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * App\model\Project
 *
 * @property int $project_id
 * @property string|null $name
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Project newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Project newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Project query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Project whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Project whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Project whereProjectId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Project whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property string|null $image
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Project whereImage($value)
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\model\TuiguangSource[] $source
 * @property string|null $is_display
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Project whereIsDisplay($value)
 * @property-read int|null $source_count
 */
class Project extends Model
{
    protected $table='project';
    protected $primaryKey='project_id';
    protected static function boot()
    {
        parent::boot();

       /* static::addGlobalScope('is_display', function (Builder $builder) {
            $builder->where('is_display', '=', 1);
        });*/
    }
    public static function getSelectOptions()
    {
        $options = \DB::table('project')->select('project_id as id','name as text')->get();
        $selectOption = [];
        foreach ($options as $option){
            $selectOption[$option->id] = $option->text;
        }
        return $selectOption;
    }
    public function user(){
        $this->hasMany(User::class,'project_id');
    }
    public function source(){
        return $this->belongsToMany(TuiguangSource::class,'tuiguang_source_project','project_id','source_id');
    }
}
